var username = document.getElementById("username");
var zip = document.getElementById("zip");
var mobile = document.getElementById("mobile");
var address = document.getElementById("address");

username.onblur = function(){checkusername()};
zip.onblur = function(){checkzip()};
mobile.onblur = function(){checkmobile()};
address.onblur = function(){checkaddress()};

var flag1 = false;
var flag2 = false;
var flag3 = false;
var flag4 = false;

function checkusername(){
	var reg_user=/^[a-zA-Z]{3,8}$/;
	var user_result = reg_user.exec(username.value);
	if(username==null||username.value==""){
		alert("用户名不能为空");
	}else if(!user_result){
		alert("请输入正确的用户名");
	}else{
		flag1 = true;
	}
}

/*判断输入的手机号码*/
function checkmobile(){
	var reg_mobile = /^[0-9]{11}/;
	var mobile_result = reg_mobile.exec(mobile.value);
	if(mobile==null||mobile.value==""){
		alert("手机号不能为空");
	}else if(!mobile_result){
		alert("不合法的手机号码");
	}else{
		flag2 = true;
	}
}

function checkzip(){
	var reg_zip = /^[0-9]{6}/;
	var zip_result = reg_zip.exec(zip.value);
	if(zip==null||zip.value==""){
		alert("邮政编码不能为空");
	}else if(!zip_result){
		alert("请输入正确的邮编");
	}else{
		flag3 = true;
	}
}

function checkaddress(){
	if(address==null||address.value==""){
		alert("收货地址不能为空");
	}else{
		flag4 = true;
	}
}

function checkAll(){
	
	var flaga = false;
	var flagb = false;
	var flagc = false;
	
	/*判断用户名输入*/
	var reg_user=/^[a-zA-Z]{3,8}$/;
	var user_result = reg_user.exec(username.value);
	if(user_result){
		flaga = true;
	}
	
	/*判断邮政编码*/
	var reg_zip = /^[0-9]{6}/;
	var zip_result = reg_zip.exec(zip.value);
	if(zip_result){
		flagb = true;
	}
	
	/*判断手机号码*/
	var reg_mobile = /^[0-9]{11}/;
	var mobile_result = reg_mobile.exec(mobile.value);
	if(mobile_result){
		flagc = true;
	}
	
	if(!flaga){
		alert("用户名错误");
		return false;
	}else if(!flagb){
		alert("邮政编码错误");
		return false;
	}else if(!flagc){
		alert("手机号码错误");
		return false;
	}else if(address==null||address.value==""){
		return false;
	}
}
